var ServerClock = function(obj){
    if(obj.container){
        var container = document.getElementById(obj.container);
        if(container){
            var spliter = (obj.spliter)?obj.spliter:':';
            var timeFormat = (obj.timeFormat)?obj.timeFormat:12;
            var tmp = new Date();
            var type = '';
            var serverTime = (obj.serverTime)?obj.serverTime:tmp.getHours()+spliter+tmp.getMinutes()+spliter+tmp.getSeconds();
            var writeTime = function(){
                var timeArray = serverTime.split(spliter);
                var seconds = parseInt(timeArray[2])+1;
                var minutes = (parseInt(timeArray[1])+Math.floor(seconds/60));
                var hours = (((type=='PM')?12:0)+parseInt(timeArray[0])+Math.floor(minutes/60))%24;
                var tmpHours = hours;
                if(timeFormat==12){
                    if(hours>=12){
                        tmpHours = tmpHours-12;
                        type='PM';
                    }else type='AM';
                }
                var seconds = seconds%60;
                var minutes = minutes%60;
                serverTime = tmpHours+spliter+minutes+spliter+seconds;
                container.innerHTML = ((tmpHours<10)?'0'+tmpHours:tmpHours)+spliter+((minutes<10)?'0'+minutes:minutes)+spliter+((seconds<10)?'0'+seconds:seconds)+' '+type;
            };
            setInterval(writeTime,1000);
        }else{
            //alert('Wrong Container Passed');
        }
    }
    else 1;//alert('No Container Passed');
}

$(document).ready(function(){
    
   
    
    new ServerClock({
        container:'clock',
        spliter:':',
        timeFormat:24,
        serverTime:$('#clock').html()
    });
})